import React from 'react';
import { Link } from 'react-router-dom';
class AddrList extends React.Component {
    constructor() {
        super();
        this.state={ 
            appData:{}
        }
    }
    componentWillMount () {
        this.setState({appData: this.props.data});
    }
   
    changedefault(e,val){
        this.props.changeDefault(val)
    }
    render() {
        return (
            <div>
                {this.state.appData.map((item, index) => {
                    return (
                        <div className=" underline addr-wrapper" key={index}>
                            <li className="flex item inf">
                                <span className="name cell-main xxl">{item.name}</span>
                                <div className="tel l">{item.tel}</div>
                            </li>
                            <span className="l ml10  ">{item.addr} {item.addrDetail}</span>
                            <div className=" item flex select-item">
                                <label className="cell-main">
                                    <input type="checkbox" className="hide" defaultChecked={item.isdefault}/>
                                    <i className="iconfont select xxl active"  onClick={e=>{this.changedefault(e,item.id)}}></i>
                                    <span className="l default mr10">默认地址</span>
                                </label>
                                <Link to={`/addrEdit/${item.id}`} className="edit l ml10">
                                    <i className="iconfont icon-bianji xxl ico-mar"></i>编辑 </Link>
                                <div className="del l ml10">
                                    <i className="iconfont icon-shanchu xxl ico-mar" onClick={e=>{this.props.delectAddr(item.id)}}></i>删除 </div>
                            </div>
                        </div>
                    )
                })}
                
            </div>
        )
    }
}
export default AddrList;